﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Framework_Tool
{
    /// <summary>
    /// Interaction logic for UnitAdd.xaml
    /// </summary>
    public partial class UnitAdd : Page
    {
        // private MainWindow main;

        public UnitAdd()
        {
            InitializeComponent();
        }

        private void UnitAdd_Click(object sender, RoutedEventArgs e)
        {
            Database.CreateUnit(this);
        }

        private void mainContent_Loaded_1(object sender, RoutedEventArgs e)
        {
            string id = Database.NextUnitID();
            unitIDAddTxt.Text = id;
            // Database.FindUnitID_Add(this);
            Database.FindStfID_UnitAdd(this);
            Database.FindCrseTitle_UnitAdd(this);

            viewUnit.FontWeight = FontWeights.Normal;
            addUnit.FontWeight = FontWeights.ExtraBold;
            updateUnit.FontWeight = FontWeights.Normal;
            deleteUnit.FontWeight = FontWeights.Normal;
            searchUnit.FontWeight = FontWeights.Normal;
        }

        public void resetUnitAdd_Click(object sender, RoutedEventArgs e)
        {
            unitAdd_StfIDCmbx.SelectedItem = null;
            unitAdd_CourseTitleCmbx.SelectedItem = null;
            crseIDAddLbl.Content = null;
            unitTitleTxt.Text = null;
            unitDescriptionTxt.Text = null;
            unitStfListBox.Items.Clear();
            unitAdd_StfNameLbl.Content = null;
        }

        public void updateUnit_Click(object sender, RoutedEventArgs e)
        {
            UnitUpdate UnitUpdateWindow = new UnitUpdate();
            UnitUpdateWindow.Content = null;
            mainContent.Children.Add(UnitUpdateWindow.mainContent);
        }

        private void deleteUnit_Click(object sender, RoutedEventArgs e)
        {
            UnitDelete stfDeleteWindow = new UnitDelete();
            stfDeleteWindow.Content = null;
            mainContent.Children.Add(stfDeleteWindow.mainContent);
        }

        private void searchUnit_Click(object sender, RoutedEventArgs e)
        {
            /*
            UnitSearch stfSearchWindow = new UnitSearch();
            stfSearchWindow.Content = null;
            mainContent.Children.Add(stfSearchWindow.mainContent);
             */
        }

        private void viewUnit_Click(object sender, RoutedEventArgs e)
        {
            UnitView stfViewWindow = new UnitView();
            stfViewWindow.Content = null;
            mainContent.Children.Add(stfViewWindow.mainContent);
        }

        private void unitAdd_StfNameCmbx_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Database.populateStfID_UnitAdd(this);
        }

        private void addTeacher_Click_1(object sender, RoutedEventArgs e)
        {
            if (!unitStfListBox.Items.Contains(unitAdd_StfIDCmbx.SelectedItem))
            {
                unitStfListBox.Items.Add(unitAdd_StfIDCmbx.SelectedItem);
            }

            unitAdd_StfIDCmbx.SelectedItem = null;
            unitAdd_StfNameLbl.Content = null;
        }

        private void removeTeacher_Click_1(object sender, RoutedEventArgs e)
        {
            unitStfListBox.Items.Remove(unitStfListBox.SelectedItem);
        }

        private void unitAdd_CourseTitleCmbx_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Database.populateCourseID_UnitAdd(this);
        }

    }
}
